



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class RulesDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public RulesDB()
        {
        }

        public RulesDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<Rules> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<Rules> lstRet = new List<Rules>();

            string strQuery = " select " + strTop  + " * from dbo.[Rules]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Rules obj = new Rules();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["RuleName"] != DBNull.Value)
                    {
                        obj.RuleName = (System.String)dr["RuleName"];
                    }
                    else
                    {
                        obj.RuleName = "";
                    } 
 if (dr["RuleNameEN"] != DBNull.Value)
                    {
                        obj.RuleNameEN = (System.String)dr["RuleNameEN"];
                    }
                    else
                    {
                        obj.RuleNameEN = "";
                    } 
 if (dr["RuleDescriptionEN"] != DBNull.Value)
                    {
                        obj.RuleDescriptionEN = (System.String)dr["RuleDescriptionEN"];
                    }
                    else
                    {
                        obj.RuleDescriptionEN = null;
                    } 
 if (dr["RuleDescriptionAR"] != DBNull.Value)
                    {
                        obj.RuleDescriptionAR = (System.String)dr["RuleDescriptionAR"];
                    }
                    else
                    {
                        obj.RuleDescriptionAR = null;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<Rules> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Rules> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , Rules obj)
        {
            
            

                    DbParameter prmRuleName = con.createParameter();
                    prmRuleName.ParameterName = "@RuleName";
                    prmRuleName.DbType =DbType.String;
                    if (obj.RuleName == null)
                    {
                        prmRuleName.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRuleName.Value = obj.RuleName;
                    }
                

                    


                    DbParameter prmRuleNameEN = con.createParameter();
                    prmRuleNameEN.ParameterName = "@RuleNameEN";
                    prmRuleNameEN.DbType =DbType.String;
                    if (obj.RuleNameEN == null)
                    {
                        prmRuleNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRuleNameEN.Value = obj.RuleNameEN;
                    }
                

                    


                    DbParameter prmRuleDescriptionEN = con.createParameter();
                    prmRuleDescriptionEN.ParameterName = "@RuleDescriptionEN";
                    prmRuleDescriptionEN.DbType =DbType.String;
                    if (obj.RuleDescriptionEN == null)
                    {
                        prmRuleDescriptionEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRuleDescriptionEN.Value = obj.RuleDescriptionEN;
                    }
                

                    


                    DbParameter prmRuleDescriptionAR = con.createParameter();
                    prmRuleDescriptionAR.ParameterName = "@RuleDescriptionAR";
                    prmRuleDescriptionAR.DbType =DbType.String;
                    if (obj.RuleDescriptionAR == null)
                    {
                        prmRuleDescriptionAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRuleDescriptionAR.Value = obj.RuleDescriptionAR;
                    }
                

                    


           



            string strQuery = " insert into dbo.[Rules] ([RuleName],[RuleNameEN],[RuleDescriptionEN],[RuleDescriptionAR]) VALUES (@RuleName,@RuleNameEN,@RuleDescriptionEN,@RuleDescriptionAR) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmRuleName,prmRuleNameEN,prmRuleDescriptionEN,prmRuleDescriptionAR);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(Rules obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, Rules obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmRuleName = con.createParameter();
                    prmRuleName.ParameterName = "@RuleName";
                    prmRuleName.DbType =DbType.String;
                    if (obj.RuleName == null)
                    {
                        prmRuleName.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRuleName.Value = obj.RuleName;
                    }
                

                    


                    DbParameter prmRuleNameEN = con.createParameter();
                    prmRuleNameEN.ParameterName = "@RuleNameEN";
                    prmRuleNameEN.DbType =DbType.String;
                    if (obj.RuleNameEN == null)
                    {
                        prmRuleNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRuleNameEN.Value = obj.RuleNameEN;
                    }
                

                    


                    DbParameter prmRuleDescriptionEN = con.createParameter();
                    prmRuleDescriptionEN.ParameterName = "@RuleDescriptionEN";
                    prmRuleDescriptionEN.DbType =DbType.String;
                    if (obj.RuleDescriptionEN == null)
                    {
                        prmRuleDescriptionEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRuleDescriptionEN.Value = obj.RuleDescriptionEN;
                    }
                

                    


                    DbParameter prmRuleDescriptionAR = con.createParameter();
                    prmRuleDescriptionAR.ParameterName = "@RuleDescriptionAR";
                    prmRuleDescriptionAR.DbType =DbType.String;
                    if (obj.RuleDescriptionAR == null)
                    {
                        prmRuleDescriptionAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRuleDescriptionAR.Value = obj.RuleDescriptionAR;
                    }
                

                    


           



            string strQuery = " update dbo.[Rules] set [RuleName]=@RuleName,[RuleNameEN]=@RuleNameEN,[RuleDescriptionEN]=@RuleDescriptionEN,[RuleDescriptionAR]=@RuleDescriptionAR where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmRuleName,prmRuleNameEN,prmRuleDescriptionEN,prmRuleDescriptionAR);

            

        }


        public void Update(Rules obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, Rules obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[Rules]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( Rules obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<Rules> getRulesByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<Rules> lstRet = new List<Rules>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<Rules> getRulesByID(System.Int64 ID)
                    {
                        List<Rules> lstRet = new List<Rules>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getRulesByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Rules> getRulesByRuleName(ClassDataHandler con,System.String RuleName)
                    {
                        List<Rules> lstRet = new List<Rules>();


                        DbParameter prmRuleName = con.createParameter();
                        prmRuleName.ParameterName = "@RuleName";
                        prmRuleName.DbType = DbType.String;
                        if (RuleName == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmRuleName.Value = RuleName;
                        }


                        lstRet = Select(con, "" , " where [RuleName]=@RuleName ", prmRuleName);



                        return lstRet;

                    }


                    public List<Rules> getRulesByRuleName(System.String RuleName)
                    {
                        List<Rules> lstRet = new List<Rules>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getRulesByRuleName(con, RuleName);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Rules> getRulesByRuleNameEN(ClassDataHandler con,System.String RuleNameEN)
                    {
                        List<Rules> lstRet = new List<Rules>();


                        DbParameter prmRuleNameEN = con.createParameter();
                        prmRuleNameEN.ParameterName = "@RuleNameEN";
                        prmRuleNameEN.DbType = DbType.String;
                        if (RuleNameEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmRuleNameEN.Value = RuleNameEN;
                        }


                        lstRet = Select(con, "" , " where [RuleNameEN]=@RuleNameEN ", prmRuleNameEN);



                        return lstRet;

                    }


                    public List<Rules> getRulesByRuleNameEN(System.String RuleNameEN)
                    {
                        List<Rules> lstRet = new List<Rules>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getRulesByRuleNameEN(con, RuleNameEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Rules> getRulesByRuleDescriptionEN(ClassDataHandler con,System.String RuleDescriptionEN)
                    {
                        List<Rules> lstRet = new List<Rules>();


                        DbParameter prmRuleDescriptionEN = con.createParameter();
                        prmRuleDescriptionEN.ParameterName = "@RuleDescriptionEN";
                        prmRuleDescriptionEN.DbType = DbType.String;
                        if (RuleDescriptionEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmRuleDescriptionEN.Value = RuleDescriptionEN;
                        }


                        lstRet = Select(con, "" , " where [RuleDescriptionEN]=@RuleDescriptionEN ", prmRuleDescriptionEN);



                        return lstRet;

                    }


                    public List<Rules> getRulesByRuleDescriptionEN(System.String RuleDescriptionEN)
                    {
                        List<Rules> lstRet = new List<Rules>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getRulesByRuleDescriptionEN(con, RuleDescriptionEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Rules> getRulesByRuleDescriptionAR(ClassDataHandler con,System.String RuleDescriptionAR)
                    {
                        List<Rules> lstRet = new List<Rules>();


                        DbParameter prmRuleDescriptionAR = con.createParameter();
                        prmRuleDescriptionAR.ParameterName = "@RuleDescriptionAR";
                        prmRuleDescriptionAR.DbType = DbType.String;
                        if (RuleDescriptionAR == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmRuleDescriptionAR.Value = RuleDescriptionAR;
                        }


                        lstRet = Select(con, "" , " where [RuleDescriptionAR]=@RuleDescriptionAR ", prmRuleDescriptionAR);



                        return lstRet;

                    }


                    public List<Rules> getRulesByRuleDescriptionAR(System.String RuleDescriptionAR)
                    {
                        List<Rules> lstRet = new List<Rules>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getRulesByRuleDescriptionAR(con, RuleDescriptionAR);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<Rules> Search(ClassDataHandler con, Rules obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.RuleName != "")
                    {
                        DbParameter prmRuleName = con.createParameter();
                        prmRuleName.ParameterName = "@RuleName";
                        prmRuleName.DbType =DbType.String;
                        if (obj.RuleName == null)
                        {
                            prmRuleName.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRuleName.Value = obj.RuleName;
                        }
                        strWhere += " [RuleName]=@RuleName AND ";
                        lstParameters.Add(prmRuleName);
                     }



                    

                    if (obj.RuleNameEN != "")
                    {
                        DbParameter prmRuleNameEN = con.createParameter();
                        prmRuleNameEN.ParameterName = "@RuleNameEN";
                        prmRuleNameEN.DbType =DbType.String;
                        if (obj.RuleNameEN == null)
                        {
                            prmRuleNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRuleNameEN.Value = obj.RuleNameEN;
                        }
                        strWhere += " [RuleNameEN]=@RuleNameEN AND ";
                        lstParameters.Add(prmRuleNameEN);
                     }



                    

                    if (obj.RuleDescriptionEN != null)
                    {
                        DbParameter prmRuleDescriptionEN = con.createParameter();
                        prmRuleDescriptionEN.ParameterName = "@RuleDescriptionEN";
                        prmRuleDescriptionEN.DbType =DbType.String;
                        if (obj.RuleDescriptionEN == null)
                        {
                            prmRuleDescriptionEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRuleDescriptionEN.Value = obj.RuleDescriptionEN;
                        }
                        strWhere += " [RuleDescriptionEN]=@RuleDescriptionEN AND ";
                        lstParameters.Add(prmRuleDescriptionEN);
                     }



                    

                    if (obj.RuleDescriptionAR != null)
                    {
                        DbParameter prmRuleDescriptionAR = con.createParameter();
                        prmRuleDescriptionAR.ParameterName = "@RuleDescriptionAR";
                        prmRuleDescriptionAR.DbType =DbType.String;
                        if (obj.RuleDescriptionAR == null)
                        {
                            prmRuleDescriptionAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRuleDescriptionAR.Value = obj.RuleDescriptionAR;
                        }
                        strWhere += " [RuleDescriptionAR]=@RuleDescriptionAR AND ";
                        lstParameters.Add(prmRuleDescriptionAR);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<Rules> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Rules> Search(Rules obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Rules> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<Rules> SearchOrLike(ClassDataHandler con, Rules obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.RuleName != "")
                    {
                        DbParameter prmRuleName = con.createParameter();
                        prmRuleName.ParameterName = "@RuleName";
                        prmRuleName.DbType =DbType.String;
                        if (obj.RuleName == null)
                        {
                            prmRuleName.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRuleName.Value = obj.RuleName;
                        }
                        strWhere += " [RuleName] LIKE @RuleName OR ";
                        lstParameters.Add(prmRuleName);
                     }



                    

                    if (obj.RuleNameEN != "")
                    {
                        DbParameter prmRuleNameEN = con.createParameter();
                        prmRuleNameEN.ParameterName = "@RuleNameEN";
                        prmRuleNameEN.DbType =DbType.String;
                        if (obj.RuleNameEN == null)
                        {
                            prmRuleNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRuleNameEN.Value = obj.RuleNameEN;
                        }
                        strWhere += " [RuleNameEN] LIKE @RuleNameEN OR ";
                        lstParameters.Add(prmRuleNameEN);
                     }



                    

                    if (obj.RuleDescriptionEN != null)
                    {
                        DbParameter prmRuleDescriptionEN = con.createParameter();
                        prmRuleDescriptionEN.ParameterName = "@RuleDescriptionEN";
                        prmRuleDescriptionEN.DbType =DbType.String;
                        if (obj.RuleDescriptionEN == null)
                        {
                            prmRuleDescriptionEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRuleDescriptionEN.Value = obj.RuleDescriptionEN;
                        }
                        strWhere += " [RuleDescriptionEN] LIKE @RuleDescriptionEN OR ";
                        lstParameters.Add(prmRuleDescriptionEN);
                     }



                    

                    if (obj.RuleDescriptionAR != null)
                    {
                        DbParameter prmRuleDescriptionAR = con.createParameter();
                        prmRuleDescriptionAR.ParameterName = "@RuleDescriptionAR";
                        prmRuleDescriptionAR.DbType =DbType.String;
                        if (obj.RuleDescriptionAR == null)
                        {
                            prmRuleDescriptionAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRuleDescriptionAR.Value = obj.RuleDescriptionAR;
                        }
                        strWhere += " [RuleDescriptionAR] LIKE @RuleDescriptionAR OR ";
                        lstParameters.Add(prmRuleDescriptionAR);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<Rules> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Rules> SearchOrLike(Rules obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Rules> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            